<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{# if(d.zt==0){ }}
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">取消申请</a>
            {{# }else{ }}
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="application">申请看房</a>
            {{# } }}
        </script>

    </div>
</div>

<script>

    layui.use(['form', 'table','miniPage','element','layarea'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;

        table.render({
            elem: '#currentTableId',
            url: SURL+'houses/queryHouseAll2',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                // {type: "checkbox", width: 50},
                {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'numbers', width: 80, title: '房屋编号'},
                {field: 'province', width: 80, title: '省'},
                {field: 'city', width: 80, title: '市'},
                {field: 'county', width: 80, title: '地区'},
                {field: 'area', width: 80, title: '面积'},
                {field: 'price', width: 80, title: '金额'},
                {field: 'address', width: 180, title: '详细地址'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            id: 'testReload',
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

       function updatebyId(id,index){
            //向后台发送数据并进行添加操作
            $.ajax({
                url:SURL+"lookhouse/update?id="+id,
                type:"POST",
                success:function(result){
                    if(result.code==200){
                        debugger;
                        layer.msg("取消成功",{
                            icon:6,
                            time:500
                        },function(){
                            parent.window.location.reload();//重新页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });

                    }else{
                        layer.msg("取消失败");
                    }
                }
            })
            return false;
      }

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'application') {
                var content = miniPage.getHrefContent('page/other/addLook.html');
                var openWH = miniPage.getOpenWidthHeight();
                var index = layer.open({
                    title: '申请看房',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['60%','60%'],
                    content: content,
                });
                //把房子id渲染
                $("#housesId").val(data.id);

                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else if (obj.event === 'delete') {

                layer.confirm('你真的要取消吗？',function (index) {
                    console.log(data.lookId)
                    updatebyId(data.lookId,index);
                })
            }
        });



    });
</script>

